package com.sinoglobal.dumping.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sinoglobal.dumping.R;
import com.sinoglobal.dumping.activity.Dumpling_MainActivity;
import com.sinoglobal.dumping.base.Dumpling_SinoAsyncTask;
import com.sinoglobal.dumping.base.Dumpling_SinoBaseFragment;
import com.sinoglobal.dumping.base.Dumpling_SinoConfig;
import com.sinoglobal.dumping.base.Dumpling_SinoConstans;
import com.sinoglobal.dumping.bean.Dumpling_ShareInfoResultList;

/**
 * Created by Administrator on 2015/10/30.
 */
public class Dumpling_MyDumplingFragment extends Dumpling_SinoBaseFragment implements View.OnClickListener {

    private View view;

    // 捞到的饺子数
    private TextView tvDumplingNums;

    // 现金
    private TextView tvCash;

    // 优惠券个数
    private TextView tvCouponNum;

    // 贺卡个数
    private TextView tvCardNum;

    private LinearLayout llLookOverDumpling;


    private Dumpling_SinoAsyncTask<Object, Void, String> queryTask;

    private Button btnShowOff;

    // 捞到的饺子个数
    private int dumplingCount;

    // 现金总数
    private double cashTotal;

    // 优惠券数
    private int couponNumber;

    // 贺卡数
    private int cardNumber;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.dumpling_my_dumpling_fragment, container, false);
        return view;
    }

    /**
     * 查询我的饺子信息
     */
//    private void queryMydumpling() {
//        queryTask = new Dumpling_SinoAsyncTask<Object, Void, Dumpling_MyDumplingBean>(getActivity(), false,true) {
//
//            @Override
//            public Dumpling_MyDumplingBean before(Object... params) throws Exception {
//                // TODO
//                return Dumpling_RemoteImpl.getInstance().queryMydumpling(Dumpling_SinoConstans.USER_ID);
//            }
//
//            @Override
//            public void after(Dumpling_MyDumplingBean result) {
//                if(!TextUtils.isEmpty(result)) {
//                    JSONObject json = JSONObject.parseObject(result);
//                    int code = json.getInteger("code");
//                    if (code == Dumpling_SinoConstans.SUCCESS_CODE) {
//
//                        JSONObject obj = json.getJSONObject("resultList");
//                        dumplingCount = obj.getInteger("count");
//
//                        if (dumplingCount > 0) {
//                            view.findViewById(R.id.id_no_fragment).setVisibility(View.GONE);
//                            view.findViewById(R.id.id_exist_fragment).setVisibility(View.VISIBLE);
//                            tvDumplingNums = (TextView) view.findViewById(R.id.tv_dumpling_nums);
//                            tvCash = (TextView) view.findViewById(R.id.tv_cash_num);
//                            tvCardNum = (TextView) view.findViewById(R.id.tv_card_num);
//                            tvCouponNum = (TextView) view.findViewById(R.id.tv_coupon_num);
//
//                            llLookOverDumpling = (LinearLayout) view.findViewById(R.id.ll_exist_look_over_dumpling);
//
//
//                            btnShowOff = (Button) view.findViewById(R.id.btn_show_off);
//                            btnShowOff.setOnClickListener(Dumpling_MyDumplingFragment.this);
//
//                            cashTotal = obj.getDouble("price");
//                            couponNumber = obj.getInteger("couponNumber");
//                            cardNumber = obj.getInteger("couponNumber");
//                            Dumpling_HttpMethodSet.getShareContent(getActivity(), Dumpling_MainActivity.TEMP_ID_STRUT, "", "", "", String.valueOf(cashTotal));
//                            tvDumplingNums.setText(String.valueOf(dumplingCount));
//                            tvCash.setText(String.valueOf(cashTotal));
//                            tvCardNum.setText(String.valueOf(cardNumber));
//                            tvCouponNum.setText(String.valueOf(couponNumber));
//
//                        } else {
//                            view.findViewById(R.id.id_no_fragment).setVisibility(View.VISIBLE);
//                            view.findViewById(R.id.id_exist_fragment).setVisibility(View.GONE);
//                            llLookOverDumpling = (LinearLayout) view.findViewById(R.id.ll_no_look_over_dumpling);
//                        }
//
//                        llLookOverDumpling.setOnClickListener(Dumpling_MyDumplingFragment.this);
//
//                    }
//
////                }
//            }
//
//            @Override
//            public void exception() {
//
//            }
//        };
//        addTask(queryTask);
//    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
//        queryMydumpling();
        executeTask();
    }

    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.findViewById(R.id.ll_exist_look_over_dumpling).setOnClickListener(this);
//        view.findViewById(R.id.ll_no_look_over_dumpling).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_show_off) {
            if (Dumpling_SinoConfig.sStrutShare!=null) {
                Dumpling_ShareInfoResultList result = Dumpling_SinoConfig.sStrutShare.getResultList();
                ((Dumpling_MainActivity) getActivity()).setShare(result.getContent(), result.getTitle(), null, result.getUrl()+"?productCode="+ Dumpling_SinoConstans.PRODUCT_CODE, 0, result.getPicurl());
            }
//        } else if (id == R.id.ll_no_look_over_dumpling) {
//            ((Dumpling_MainActivity) getActivity()).setTabHost();
        } else if (id == R.id.ll_exist_look_over_dumpling) {
            ((Dumpling_MainActivity) getActivity()).setTabHost();
        }
    }

}
